<?php
namespace App\Traits\Templates;

// 厨房打印模板 对应型号 w1
trait KitchenTemplate
{
	protected $kitchenSingleData = [
		'order_number' => '20201110',
		'cashier' => '阿伟',
		'created_at' => '10/11 12:00',
		'goods' => [
			'name' => '盐焗鸡',
			'price' => 29,
			'number' => 1
		]
	];
	protected $kitchenOrderDate = [
		'room_id' => '超大房A5',
		'order_id' => '2020111200',
		'cashier' => '阿伟',
		'created_at' => '2020/11/10 12:00',
		'printed_at' => '2020/11/10 12:00',
		'goods' => [
			[
				'name' => '欢乐炸鸡',
				'number' => 2,
			],
			[
				'name' => '欢乐烤鸭',
				'number' => 1,
			]
		]
	];
	// 厨房商品分单
	public function KitchenSingleTemplate($data = [])
	{
		$heads  = '<FS2><LR>,NO:'.$data['order_number'].'</LR></FS2>';
		$heads .= '<LR>收银员：'.$data['cashier'].'</LR>';
		$heads .= '<center>----------------------------------------</center>';
		$heads .= '<FS2><LR>'.$data['goods']['name'].',</LR></FS2>';
		$heads .= '<table><tr><td> </td><td>'.$data['goods']['number'].' 份</td><td>'.$data['goods']['price'].'元</td></tr></table>';
		$heads .= '<center>----------------------------------------</center>';
		$heads .= '<table><tr><td>小计：</td><td><FS2>'.$data['goods']['number'] * $data['goods']['price'].'元</FS2></td><td>'.$data['created_at'].'</td></tr></table>';
		$heads .= '<LR>出品点：厨房,</LR>';

		return $heads;
	}

	// 厨房商品总单
	public function KitchenOrderTemplate($data = [])
	{
		// 页首
		$heads  = '<center>@@2点单[后厨-厨总单]</center>';
		$heads .= '<LR>桌台号：,'.$data['room_id'].'</LR>';
		$heads .= '<LR>流水号:'.$data['order_id'].',</LR>';
        //$heads .= '<LR>出单序号:,7</LR>';
		$heads .= '<center>----------------------------------------</center>';
		$heads .= '<LR>商品,数量</LR>';

		// 商品主体
		$order  = '<table>';
		foreach($data['goods'] as $k => $v){
			static $count = 0;
			$index  = $k + 1;
			$order .= '<tr><td>'.$index.'</td><td>'.$v['name'].'</td><td>'.$v['number'].'/份</td></tr>';
			$count += $v['number'];
		}
		$order .= '</table>';

		// footer 
		$footer  = '<center>----------------------------------------</center>';
		$footer .= '<LR>合计, '.$count.'</LR>';
		$footer .= '<center>----------------------------------------</center>';
		$footer .= '<LR>收银员:'.$data['cashier'].',</LR>';
		$footer .= '<LR>开单:'.$data['created_at'].', 出单:'.$data['printed_at'].'</LR>';

		return  $heads . $order . $footer;
	}
}